package com.cn.wanxi.dao.impl;

import com.cn.wanxi.dao.CompanyFindAllDao;
import com.cn.wanxi.model.CompanyModel;
import com.cn.wanxi.util.JDBC;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

public class CompanyFindAllImpl implements CompanyFindAllDao {
    @Override
    public List<CompanyModel> findAll(CompanyModel companyModel) {
        return null;
    }

    @Override
    public int add(CompanyModel companyModel) {
        return 0;
    }

    @Override
    public int update(CompanyModel companyModel) {
        return 0;
    }

    @Override
    public CompanyModel findById(CompanyModel companyModel) {
        return null;
    }

    @Override
    public int delete(CompanyModel companyModel) {
        return 0;
    }

    @Override
    public int getCount(CompanyModel companyModel) {
        return 0;
    }

    @Override
    public CompanyModel findCompany() {
        String sql = "select * from company where enable = 1 and is_show = 1 ";
        ResultSet resultSet = JDBC.query(sql);
        CompanyModel model = null;
        try {
            while (resultSet.next()) {
                model = new CompanyModel();
                model.setId(resultSet.getInt("id"));
                model.setLogo(resultSet.getString("logo"));
                model.setPhone(resultSet.getString("phone"));
                model.setAd(resultSet.getString("ad"));
                model.setNet(resultSet.getString("net"));
                model.setEmail(resultSet.getString("email"));
                model.setLinePhone(resultSet.getString("line_phone"));
                model.setVersion(resultSet.getString("version"));
                model.setAddress(resultSet.getString("address"));
                model.setIsShow(resultSet.getInt("is_show"));
                model.setCreateTime(resultSet.getString("create_time"));
                model.setEnable(resultSet.getInt("enable"));
                model.setAdvertisement(resultSet.getString("advertisement"));
                model.setName(resultSet.getString("name"));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return model;
    }
}
